package com.foryou.wechat.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <h1>Controller 统一的响应</h1>
 * Created by Lee.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response {

    /** 错误码: 正确返回 0 */
    private int code = 0;

    /** 错误信息，正确返回空字符串 */
    private String msg = "success";

    /** 返回值对象 */
    private Object data;

    /**
     * <h2>正确的响应构造函数</h2>
     * */
    public Response(Object data) {
        this.data = data;
    }


    /**
     * <h2>正确的响应构造函数</h2>
     * */
    public Response(Object data,String msg) {
        this.msg = msg;
        this.data = data;
    }

    /**
     * <h2>空响应</h2>
     * */
    public static Response success() {
        return new Response();
    }

    /**
     * <h2>带返回值的响应</h2>
     */
    public static Response success(Object data) {
        return new Response(data);
    }

    /**
     * <h2>带返回值的响应</h2>
     */
    public static Response success(Object data,String msg) {
        return new Response(data,msg);
    }

    /**
     * <h2>错误响应</h2>
     * */
    public static Response failure(String msg) {
        return new Response(-1, msg, null);
    }

    /**
     * <h2>错误响应</h2>
     * */
    public static Response failure(int code,String msg) {
        return new Response(code, msg, null);
    }


}